/** MD合集,把基础按键都放到不用的地方,所有使用的键都是热键,这样才满足
  多个游戏的需求.基础按键依次为:a,b,c,start
 
  By setycyas @2025-05-07
*/

/* 全局设定
*/ {
#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\MyEmu.2.ahk"
#Include "..\Class\OrderMap.2.ahk"
;#Include "..\Class\DrawWindow.2.ahk"
;SendMode("Event")
SendMode("Input")
}

/* 制作Md的宏类
*/ class MdMacro extends CommonMacro {

  pressDuration := 30

  /* 函数
  */

  /* 新增的宏函数
  */
  ;单发
  _单宏模拟(i, key){
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    this._down(i)
	  sleep(this.autoFireDelay)
    loop {
	    sleep(this.autoFireDelay)
    } until (not MyFuns.getVkState(vk))
    this._up(i)
  }
  _单发A(key){
    this._单宏模拟(1, key)
  }
  _单发B(key){
    this._单宏模拟(2, key)
  }
  _单发C(key){
    this._单宏模拟(3, key)
  }
  _单发start(key){
    this._单宏模拟(4, key)
  }
  ;蓄力
  _蓄力A(key){
    this._down(1)
  }
  _蓄力B(key){
    this._down(2)
  }
  _蓄力C(key){
    this._down(3)
  }
  ;轻微位移用
  _右微移(key){
    MyFuns.press("right", 50)
    sleep(50)
  }
  _左微移(key){
    MyFuns.press("left", 50)
    sleep(50)
  }
  ;其他
  
  
  /* 重载宏接口
  */
  _setMacro(){
    static obm := ObjBindMethod ;函数名简写,制作对象绑定函数
    local m := OrderMap() ;this.macroMap的简写
    ;制作宏相关Map
    this.macroMap := m
    ;常规
    m["连发A"] := obm(this, "_连发A")
    m["连发B"] := obm(this, "_连发B")
    m["连发C"] := obm(this, "_连发C")
    m["单发A"] := obm(this, "_单发A")
    m["单发B"] := obm(this, "_单发B")
    m["单发C"] := obm(this, "_单发C")
    m["单发start"] := obm(this, "_单发start")
    m["蓄力A"] := obm(this, "_蓄力A")
    m["蓄力B"] := obm(this, "_蓄力B")
    m["蓄力C"] := obm(this, "_蓄力C")
    m["左微移"] := obm(this, "_左微移")
    m["右微移"] := obm(this, "_右微移")
    m["空函数"] := obm(this, "_空函数")
    ;特殊游戏专用
    ;制作指定宏顺序的数组
    this.macroArr := m.getKeys()
  }
}

/* 制作Md专用UI
*/
class MdUI extends CommonUI {

  HOTKEY_NUM := 8
  EXE_ARRAY := [MyEmu.MAME, MyEmu.XZONE]
  
  /* 构造函数
  */
  __New(macro){
    super.__New("Md合集", macro)
    local i, v
    this._preset := OrderMap()
    this._macro.UI := this ;绑定UI
    ;设置preset和提升蓄力宏的优先级
    this._preset["默认"] := ["连发B", "单发C", "单发B", "连发C", 
      "单发A", "左微移", "右微移", "单发start"
    ]
    this._preset["怒之铁拳"] := ["连发B", "单发C", "单发B", "连发C", 
      "单发A", "蓄力B", "蓄力B", "单发A"
    ]    
  }

  /* 重写接口
  */
  ;自定义gui组件标签页,增加一个挡板召唤键
  _customGui(){
    super._customGui()
    ;增加mame窗口变换按键
    this._mameWindowButton := this._myGui.Add("Button", "Default w200", "mame窗口变换")
    this._mameWindowButton.OnEvent(
      "Click", 
      ObjBindMethod(this, "_Mame窗口变换")
    )
  }

  /* 重写setup,更改可选的exe,读入预设
  */
  setup(){
    super.setup()
    this._myGui.opt("+AlwaysOnTop")
    this._myGui.show("x1100 y230")
    this.readPresetMenu("默认")
  }
  
  /* 自定义函数
  */
  ;mame窗口变换响应函数
  _Mame窗口变换(btnObj, info){
    static W_TITLE := "ahk_exe mame.exe"
    static HEIGHT := 240*2.5+30
    static WIDTH := 320*2.5
    static X:= Round((1366-WIDTH)/2)-50
    static Y:= Round((768-HEIGHT)/2)
    ;执行
    MyFuns.setWindow(W_TITLE, WIDTH, HEIGHT, X, Y)
  }
  
}

/* 运行当前脚本
*/ 
if (A_ScriptName == "MD合集.2.ahk") {
  ;iconFile := "..\Icon\怒首领蜂最大往生_光头像01.jpg"
  ;TraySetIcon(iconFile, , 1)

  face := FaceDetector() ;方向检测对象
  macro := MdMacro(face, ["i","k","l","1"]) ;宏对象,有界面时第二个参数可以随便写但长度不要小于2
  ;新建界面对象并显示
  ui := MdUI(macro)
  ui.setup()
  ;更新组件内容
  ui._exeComboBox.Choose(MyEmu.MAME)
  ;ui._exeComboBox.Choose(MyEmu.FBNEO64)
  ui._gameKeyEdit.Text := "i,k,l,1"
  ui._hotkeyEdit.Text := "~s,~d,~x,~c,~a,~w,~e,~space"
  ui._fpsEdit.Text := 15
  ui._testEdit.Text := "30,20,30,30"
  ui.readPresetMenu("默认")
}
